const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const webpack = require('webpack')
module.exports = {
  mode: 'development',
  entry: path.resolve(__dirname, './src/main.js'),
  devtool: 'cheap-module-source-map',
  // cheap-module-eval-source-map
  output: {
    filename: 'output.js',      // 打包后的文件名称
    path: path.resolve(__dirname, './dist')  // 打包后的目录
  },
  // loader
  module: {
    rules: [
      {
        test: /\.(c|sc|sa)ss$/,
        use: [
          "style-loader",
          "css-loader",
          "sass-loader"
        ]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
      }
    ]
  },

  devServer: {
    contentBase: './dist',
    open: true,
    port: 3000,
    hot: true,
    hotOnly: true
  },
  // 优化  tree shaking
  optimization: {
    usedExports: false
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, './public/index.html')
    })
  ]
}